﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ecdl.demo.model.expression {
    public delegate IEnumerable<Out> Selection<In, Out>(In context);

    public interface ITypeSelector {
         Type InType { get; }
         IEnumerable<object> DoSelect(object context);
    }

    public class TypedSelector<In, Out> : ITypeSelector{
        private event Selection<In,Out> select;

        public TypedSelector(Selection<In, Out> selector) {
            this.select = selector;
        }

        public Type InType {
            get {
                return typeof(In);
            }
        }

        public IEnumerable<object> DoSelect(object context) {
            if (context != null) {
                return (IEnumerable<object>) this.select((In)context);
            }
            //return an empty list
            return new List<object>();
        }
    }
}
